#ifndef __FINITE_STATE_MACHINE_H__
#define __FINITE_STATE_MACHINE_H__

#include <cstdio>

#include "my_types.h"

enum state_t
{
    STATE_DATA,
    STATE_IAC,
    STATE_OPTION,
    STATE_SUBOPTION
};

enum verb_t
{
    VERB_WILL,
    VERB_WONT,
    VERB_DO,
    VERB_DONT
};

enum option_t
{
    ECHO = 1,      //回显
    SGA = 3,       //抑制继续执行
    TERMTYPE = 24, //终端类型
    NAWS = 31,     //窗口大小
    TSPEED = 32,   //终端速率
    LFLOW = 33,    //流量控制
    LINEMODE = 34, //行方式
    ENVIRON = 36,  //环境变量
    STATUS = 5     //状态

};
enum
{
    IS = 0,
    SEND = 1
};

#define IAC 255
#define WILL 251
#define WONT 252
#define DO 253
#define DONT 254
#define SB 250
#define SE 240

class finite_state_machine_t
{
private:
    state_t state = STATE_DATA;
    verb_t verb;
    int *if_support;

public:
    void (*process_data)(uchar);
    void (*deal_ECHO)(uchar verb);
    void (*deal_SGA)(uchar verb);
    void (*deal_TERMTYPE)(uchar verb);
    void (*deal_ENVIRON)(uchar verb);
    void (*deal_LINEMODE)(uchar verb);
    void (*deal_NAWS)(uchar verb);
    void (*deal_STATUS)(uchar verb);
    void (*deal_TSPEED)(uchar verb);
    void (*deal_LFLOW)(uchar verb);
    void (*send_pass)(uchar verb, uchar option);
    void (*send_term_type)();

    void operator()(uchar ch);
};

#endif //__FINITE_STATE_MACHINE_H__